#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
using ull = unsigned long long;
const int N = 1005, M = 1005;
const int P1 = 131, P2 = 233;
int n, m, a, b, q;
char c[N][N], d[N][N];
ull hash1[N][N], hash2[N][N];
set<ull> ans;
ull p1[N], p2[N];

void init() {
  p1[0] = p2[0] = 1;
  rep(i, 1, n) p1[i] = p1[i - 1] * P1;
  rep(j, 1, m) p2[j] = p2[j - 1] * P2;
}
void init_hash1() {
  rep(i, 1, n) {
    rep(j, 1, m) { hash1[i][j] = hash1[i][j - 1] * P2 + c[i][j] - '0'; }
    rep(j, 1, m) { hash1[i][j] = hash1[i - 1][j] * P1 + hash1[i][j]; }
  }
}
void init_hash2() {
  rep(i, 1, a) {
    rep(j, 1, b) { hash2[i][j] = hash2[i][j - 1] * P2 + d[i][j] - '0'; }
    rep(j, 1, b) { hash2[i][j] = hash2[i - 1][j] * P1 + hash2[i][j]; }
  }
}
void init_ans() {
  rep(i, a, n) rep(j, b, m) {
    ull now = hash1[i][j];
    now -= hash1[i - a][j] * p1[a];
    now -= hash1[i][j - b] * p2[b];
    now += hash1[i - a][j - b] * p1[a] * p2[b];
    ans.insert(now);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> a >> b;
  init();
  rep(i, 1, n) rep(j, 1, m) cin >> c[i][j];
  init_hash1();
  init_ans();
  cin >> q;
  while (q--) {
    rep(i, 1, a) rep(j, 1, b) cin >> d[i][j];
    init_hash2();
    if (ans.count(hash2[a][b]))
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}